package com.interview.javabase.gc;

/**
 * @author: zsg
 * @description:
 * @date: 2019/6/23 20:18
 * @modified:
 */
public class Finalization {
    private  static Finalization finalization;

    @Override
    protected void finalize() throws Throwable {
        System.out.println("finalize");
        finalization =this;
    }

    public static void main(String[] args) {
        Finalization f = new Finalization();
        System.out.println("first: "+f);
        f = null;
        System.gc();
        // 让上面的垃圾回收线程有足够多时间完成垃圾回收
        try {
           Thread.sleep(1000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        System.out.println("second: "+f);
        System.out.println(f.finalization);
    }
}

